#include <iostream>

#include <muduo/net/TcpServer.h>
#include "HttpRequest.h"
#include "HttpResponse.h"
namespace http
{
    class HttpContext
    // 解析报文并构建请求和响应对象 封装到HttpRequest和HttpResponse中
    {
    public:
        enum HttpRequestParseState
        {
            ExpectRequestLine,    // 解析请求行
            ExpectRequestHeaders, // 解析请求头
            ExpectRequestBody,    // 解析请求体
            ExpectRequestComplete // 解析请求完成
        };
        bool parseRequest(muduo::net::Buffer *buffer, muduo::Timestamp receive_time); // 解析请求
        HttpContext();
        bool isComplete() const { return _request_parse_state == ExpectRequestComplete; } // 检查是否解析完成
        const HttpRequest &getRequest() const { return _request; }                        // 获取解析后的请求对象
        void reset();// 重置解析状态
    private:
        bool processRequestLine(const char *begin, const char *end);

        HttpRequestParseState _request_parse_state; // 请求解析状态
        HttpRequest _request;                       // 请求对象
    };
}